<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>编辑管理员</title>
	<link rel="stylesheet" href="/admin/src/css/layui.css">
</head>

<body >
	<form class="layui-form " style="margin:20px auto;">
		<div class="layui-form-item">
			<label class="layui-form-label">身份名称</label>
			<div class="layui-input-inline">
				<input type="text" name="role_name" id="role_name" value="{$roleInfo['role_name']}" lay-verify="required" placeholder="请输入身份名称" autocomplete="off" class="layui-input">
				<input type="hidden" name="role_id" id="role_id" value="{$roleInfo['role_id']}">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">身份状态</label>
		    <div class="layui-input-block">
				<input type="radio" name="status" value="1" title="显示" {$roleInfo['status'] == 1 ? 'checked' : ''}>
				<input type="radio" name="status" value="0" title="隐藏" {$roleInfo['status'] == 0 ? 'checked' : ''}>
		    </div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">身份权限</label>
		    <div id="powerList" class="demo-tree-more layui-input-inline"></div>
		</div>
	  <div class="layui-form-item">
	    <div class="layui-input-block">
	      <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
	    </div>
	  </div>
	</form>
	<script src="/admin/src/layui.js" ></script>
<script>
	var infoStatus = '{$infoStatus}'
    layui.use(['form','jquery','tree'], function(){
      var form = layui.form ,
		  layer = layui.layer,
		  tree = layui.tree,
		  $= layui.jquery;
		  
      if(infoStatus == 0){
		  layer.msg('获取不到对应的信息',{time:1000},function(){
		  		window.parent.frames.location.href="/admin/role/index"
		  })
	  }
	  var roleId = '{$roleInfo['role_id']}';
	  $.ajax({
	  	url : '/admin/role/edit/form',
	  	type : 'get',
	  	dataType : 'json',
	  	contentType :"application/json",
	  	data : {'getTree':'getTree','role_id':roleId},
	  	success : function (backData) {
	  	  if(backData['status'] == 200){
	  		  var formaData = backData['data']
	  		  //基本演示
				tree.render({
					elem: '#powerList'
					,data: formaData
					,showCheckbox: true  //是否显示复选框
					,id: 'powerListId'
					,isJump: false //是否允许点击节点时弹出新窗口跳转
					,click: function(obj){
						var data = obj.data;  //获取当前点击的节点数据
						//layer.msg('状态：'+ obj.state + '<br>节点数据：' + JSON.stringify(data));
					}
				});
	  	  }
	  	}
	  })
	  
	  $(".downpanel").on("click",".layui-select-title",function(e){
		  var $select=$(this).parents(".layui-form-select");

		  $(".layui-form-select").not($select).removeClass("layui-form-selected");
		  $select.addClass("layui-form-selected");
		  e.stopPropagation();
	  }).on("click",".layui-form-checkbox",function(e){
		  e.stopPropagation();
	  });

	  
      //监听表单提交
      form.on('submit(formDemo)', function(data){
		var postData = data.field;
		$.ajax({
			url: '/admin/role/update/data',
			type: 'POST',
			data:postData,
			success : function (backData) {
			  if(backData['status'] == 200){
				  layer.msg(backData.message,{time:1200},function(){
					  window.parent.frames.location.href="/admin/role/index"
				  })
				  
			  }else{
				  layer.msg(backData.message);
			  }
			}
		})
        return false;
      });
    });

</script>
</body>
</html>
